package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.manger.config.BeautyMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_BEAUTY_SHOW_MARK, desc = "美女展示标记")
public class BeautyShowMarkCmd extends AbstractCommand {

    private int beautyId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyProto.BeautyShowMarkReqMsg reqMsg = BeautyProto.BeautyShowMarkReqMsg.parseFrom(packet.getBytes());
        beautyId = reqMsg.getBeautyId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        UserBeauty userBeauty = player.getModule(BeautyModule.class).getUserBeauty(beautyId);
        if(!BeautyMgr.isUserBeautyExist(userBeauty)){
            ret = GameErrorCode.E_BEAUTY_NO_FOUND;
            return;
        }
        userBeauty.setShow(true);
        player.getModule(BeautyModule.class).syncUserBeauty(userBeauty);
    }

    @Override
    public void sendData(GamePlayer player) {
        BeautyProto.BeautyShowMarkRespMsg.Builder respMsg = BeautyProto.BeautyShowMarkRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_BEAUTY_SHOW_MARK, respMsg);
    }
}
